﻿// JScript 文件
//定义全局变量
//var xmlhttp=GetAjaxObject();
var divobj=document.getElementById("desc");
var url="http://www.cnblogs.com/me-sa/Rss.aspx";
var title=[];
var link=[]; 
var pubDate=[];
var description=[];
var ServiceUrl="/Passport/UserReg.aspx";

//获取XML
function GetAjaxObject(){
  var httprequest=false;
  if(window.XMLHttpRequest){
     httprequest=new XMLHttpRequest();
     if(httprequest.overrideMimeType){
        httprequest.overrideMimeType('text/xml');
     }
  }
  else if(window.ActiveXObject){
     try{
        httprequest=new ActiveXObject("Msxml2.XMLHTTP");
        
     }
     catch(e){
       try{
          httprequest=new ActiveXObject("Microsoft.XMLHTTP");
       }
       catch(e){}
     }  
  }
  return httprequest;
}
function loginUser()
{
   var UserName=escape($("UserName").value);
   var Password=escape($("Password").value);
   if(UserName==""||Password==""){
       window.alert("用户名或密码不能为空");
       return false;
  }
  
  var ajaxobj=GetAjaxObject();
  ajaxobj.open("GET","Login.aspx?UserName="+UserName+"&UserPassword="+Password+"&EncodeType=utf8&Rnds="+Math.random(),true);
  
  ajaxobj.onreadystatechange=function()
  {
     if(ajaxobj.readystate==4)
     {  
        if(ajaxobj.status==200)
        {    
            var returntext="";   
			if(getCookie("Howave_UnicodeUserName")!=null){
                ShowLoginSuccess();
                ShowTopLoginSuccess();
			}else{
				window.alert("登录失败，用户名或密码错！");
			}
            $("UserName").value="";
            $("Password").value="";
          
        }    	 
     }
  }
  ajaxobj.send(null);
 
}
function $(id)
{
  return document.getElementById(id);
} 
function RegUser()
{
   var UserName=escape($("RegUserName").value);
   var Password=escape($("RegPassword").value);
   var RePassword=escape($("ConfirmPassword").value);
   var Email=escape($("RegEmail").value);
   var CheckCode=escape($("RegCheckCode").value);
   if(UserName=="" || Password=="" || RePassword=="" ||Email=="" ||CheckCode=="")
   {
      alert("注册项不能为空");
      return;
    }
    else if(Password!=RePassword)
    {
      alert("两次输入密码不相同");
      return;
    }
    else if(Password.length<6 ||Password.length>16)
    {
       alert("密码位数不正确");
       $("RegPassword").focus();
       return;
    }
    else if(!chkemail(Email))
    {
      alert("邮箱格式不正确");
      $("RegEmail").focus();
      return;
    }
    var ajaxobj2=GetAjaxObject();
   ajaxobj2.open("GET","UserReg.aspx?UserName="+UserName+"&Password="+Password+"&Email="+Email+"&CheckCode="+CheckCode+"&Answer=&Question=&EncodeType=utf8&Rnds="+Math.random(),true);
  
  ajaxobj2.onreadystatechange=function()
  {
     if(ajaxobj2.readystate==4)
     {  
        if(ajaxobj2.status==200)
        {          
           var returntext=ajaxobj2.responseText;
           alert(returntext);
          
        }    	 
     }
  }
  ajaxobj2.send(null);
}
function ClearReg()
{
  $("RegUserName").value=$("RegPassword").value=$("ConfirmPassword").value=$("RegEmail").value=$("RegCheckCode").value="";
}    
function logoutUser()
{
//	  var usercookie=getCookie("Howave_UserName");
//	  if(usercookie==""||usercookie==null)
//	     return;
//	  else
//	  {
//	      
//	                    
//	  }
       var ajaxobjs=GetAjaxObject();
	      ajaxobjs.open("GET","Logout.aspx?Rnd="+Math.random(),true);
	      ajaxobjs.onreadystatechange=function()
	      {
	           if(ajaxobjs.readystate==4)
	           {   
	             
	              if(ajaxobjs.status==200)
	              {  
	                 ShowLogin();
	               }
	           }
	      }
	      ajaxobjs.send(null);
	    
	  
}
function CheckUserLogin()
{
    var LoginUserName=getCookie("Howave_UserName");
    if(LoginUserName!=""&&LoginUserName!=null)
    {    
    
       ShowLoginSuccess();      
               
    }
    else
    {      
       ShowLogin();
    }  
}
function CheckIndexLogin()
{
    var LoginUserName=getCookie("Howave_UserName");
    if(LoginUserName!=""&&LoginUserName!=null)
    {    
       ShowTopLoginSuccess();
    }
   
}

var _regUserNameOld;
function CheckRegName(ctl,displayId,RegNameMin,RegNameMax)
{
    var regname = $(ctl).value;

  if(regname==""||regname==null)
  {
     $("reg_UserName").className="reg_tips_empty";
     $(displayId).innerHTML="用户名不能为空";
     return;
  }
  else {
    if(_regUserNameOld==regname)
       return;
    else 
      _regUserNameOld=regname;
}



var strTest = /^[a-zA-Z]{1}([a-zA-Z0-9]){4,20}[a-zA-Z0-9]{1}$/;
var strXiahua = /^([a-zA-Z]|\d|_)*$/;
if (!strTest.test(regname)&&!strXiahua.test(regname)) {
    $("reg_UserName").className = "reg_tips_empty";
    $(displayId).innerHTML = "输入的字符格式不对";
    return;
}
  
//  if(!CheckSQLInj(regname)){
//    $(displayId).innerHTML="用户名有非法字符，请重新输入";
//    return;
//  }
   var regnameLength=regname.length;
//   if (regname.match(/[^\u4e00-\u9fa5]/g))//匹配中文
//   {
//      regnameLength=regnameLength*2;
//      
//    }

   if(regnameLength<4)
   {
      $("reg_UserName").className="reg_tips_empty";
      $(displayId).innerHTML="&nbsp;用户名长度不正确";
      return;
   }
     
   regname=escape(regname);
   $(displayId).innerHTML="<img src=\"../images/Loading.gif\"/>正在连接数据库...";
   var ajaxobj=GetAjaxObject();
   var submitURL=ServiceUrl+"?Action=CheckReg&UserName="+regname+"&RegNameMin="+RegNameMin+"&RegNameMax="+RegNameMax+"&Rnd="+Math.random();
   ajaxobj.open('GET',submitURL,true); 
   ajaxobj.send(null);
   ajaxobj.onreadystatechange=function()
   {
      var _state=0;
      if(ajaxobj.readystate==undefined){
          _state=4;
      }else{
          _state = ajaxobj.readystate;
      }
      if(_state==4)
      { 
         if(ajaxobj.status==200)
         { 
            if(ajaxobj.responseText=="True"){
               $("reg_UserName").className="reg_tips_onchange";
               $(displayId).innerHTML="&nbsp;该用户名可以注册";
            }
            else if(ajaxobj.responseText=="lengthwrong")
            {
                $("reg_UserName").className="reg_tips_empty";
                $(displayId).innerHTML="&nbsp;用户名长度格式不正确，请确保在"+RegNameMin+"和"+RegNameMax+"字符之间。";
            }  
            else{
               $("reg_UserName").className="reg_tips_empty";
               $(displayId).innerHTML="&nbsp;该用户名已经被其他人注册";
               
            }   
         }else{
             $("reg_UserName").className="reg_tips_empty";
             $(displayId).innerHTML="&nbsp;连接不成功，无法判断用户名是否已存在！";
         }
      }   
   }
   
   
}
function CheckSQLInj(str) 
{ 
    re= /select|update|delete|exec|count|'|"|=|;|>|<|%/i;
    if (re.test(str) ) 
      return false; 
    
}



function ShowLogin()
{
      // document.getElementById("showlogin").style.display="";
       $("showloginsuccess").style.display="none"; 
       ClearRssList();
}   



//显示隐藏Rss
function showhide(objID)
{
   var obj=$(objID);
   obj.style.display=obj.style.display=="none"?"":"none";
}



function getCookie(cookieName)
{
    var cookieString = document.cookie
    var first ,last
    first=cookieString.indexOf(cookieName)
    if(first!=-1)
    {
       first+=(cookieName.length+1)
       last=cookieString.indexOf(';',first);
       
       return unescape(cookieString.substring(first,last));
    }
    return null;
    
}


function GoSearch()
{
   var searchKey=$("WebSearch").value
   if(searchKey==""||searchKey==null)
   { 
      window.alert("搜索内容不能为空");
      return false;
   }   
   if($("Google").checked)
      var arr=showModalDialog('http://www.google.com/search?hl=zh-CN&inlang=zh-CN&ie=GB2312&oe=GB2312&q='+searchKey,'','dialogWidth:800px; dialogHeight:600px; help: yes; scroll: yes; status: no;');
   if(document.getElementById("Baidu").checked)
      var arr=showModalDialog('http://www1.baidu.com/baidu?tn=verywind&word='+searchKey,'','dialogWidth:800px; dialogHeight:600px; help: yes; scroll: yes; status: no;');
   if(document.getElementById("Yahoo").checked)
      var arr=showModalDialog('http://www.yahoo.com.cn/search?p='+searchKey,'','dialogWidth:800px; dialogHeight:600px; help: yes; scroll: yes; status: no;');
   return false;
}
function ShowTopLoginSuccess()
{
  $("toolbar_login").style.display="none";
  $("toolbar_welcome").style.display="";
  var text= $("toolbar_welcome").innerHTML;
  if(text=="")
  {
     $("toolbar_welcome").innerHTML="欢迎：<b style='color:red;font-size:13px'>"+getCookie("Howave_UnicodeUserName")+"</b>&nbsp;&nbsp;<a href='Logout.aspx'>注销</a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick='return initContent(\"ManageSiteMessage.aspx\")'>短消息</a>";
  }
}
function ShowLoginSuccess()
{
	   $("showlogin").style.display="none";
       $("showloginsuccess").style.display="";
       var text= $("welocme").innerHTML;
       if(text=="")
       {
          text="欢迎：";
          $("welocme").innerHTML=text+getCookie("Howave_UnicodeUserName")+"</br><div style='text-align:center'>&nbsp;&nbsp;异步登录后需在导航栏点击相应系统进入才可激活该系统<a href='Logout.aspx'>注销</a></div>";
       }else{
		  text = "登陆失败，用户名或密码错！";
	   }
      
    
}
function ShowDefaultHide()
{   
    if($('leftmenu') != null)
    {
	    if($('leftmenu').style.display == 'none')
	    {
		    $('leftmenu').style.display='inline';
		    $('sideBar2').style.display='inline';
	    }
	    if($('leftarea') != null)
	    {
	       $('leftmenu').innerHTML = $('leftarea').innerHTML;	 
	       $('leftarea').innerHTML = '';
	    }
    }
}

function chkemail(a)
{	var i=a.length;
	var temp = a.indexOf('@');
	var all = a.substring(temp);
	var tempd = all.indexOf('.')+temp;
	if (temp > 1) {
	  return 1;
	}
	return 0;
}
function ChangeStyle(color)
{
  switch(color)
  {
    case "red":
      $("toolbar").style.backgroundImage="url(Images/dialog/toolbar_red_bg.gif)";     
      break;
    case "blue":
      $("toolbar").style.backgroundImage="url(Images/dialog/toolbar_blue_bg.gif)";     
      break;
    case "green":
      $("toolbar").style.backgroundImage="url(Images/dialog/toolbar_green_bg.gif)";     
      break;
    case "orange":
      $("toolbar").style.backgroundImage="url(Images/dialog/toolbar_orange_bg.gif)";     
      break;
    default:
      $("toolbar").style.backgroundImage="url(Images/dialog/toolbar_bg.gif)";     
      break;     
  }
  SetCookie("toolbarBg",color,30);
}
function SetCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	
}
function showToolbar()
{
  var toolbarObj=$("toolbar");
  toolbarObj.style.display="";
}
var fix=0;
function fixToolbar(fixed)
{
  if(fixed==1)
  {
    fix=1;
    $("toolbar").style.position="relative";
  }
  else if(fixed==0)
  {
   fix=0;
   $("toolbar").style.position="absolute";
  }
  if(fix==0)
  {
    $("toolbar").style.display="none";   
  }
  else
  {
    $("toolbar").style.display="";   
  }
}
function ShowTime()
{
  var d = new Date();
  var vHour = d.getHours();
  var vMin = d.getMinutes();
  var vSec = d.getSeconds();  
  $("time").innerHTML=vHour+":"+vMin+":"+vSec;
  setTimeout("test()",1000);
}
function Active()
{
  parent.ActivePage.location="Index.aspx";
  setTimeout("Active()",300000);//1000表示1秒，表示5分钟从后台激活一次asp.net,这里时间随你系统的配置而更改。主要是保持页面不用重新加载
}    
//检测通行证用户登录
function CheckLogin(){
   var uObj=$("UserName");
   var pObj=$("UserPassword");
   if(uObj!=null){
      if(uObj.value.length<1 || uObj.value==''){
          $("err1").style.display='';
          return false;
      }
   }
   if(pObj!=null){
      if(pObj.value.length<3 || pObj.value==''){
          $("err2").style.display='';
          return false;
      }
   }
   return true;
}